package com.gyhy.dumplings.customer.controller;

import com.gyhy.dumplings.common.exception.BizCodeEnum;
import com.gyhy.dumplings.common.utils.R;
import com.gyhy.dumplings.common.vo.SocialUser;
import com.gyhy.dumplings.customer.entity.CustomerEntity;
import com.gyhy.dumplings.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: 光影灰翼
 * @date: 2022-09-16 7:54
 * @version: 1.0
 * @email: 978330688@qq.com
 */
@RestController
@RequestMapping("/customer/customer")
public class CustomerController {


    @Autowired
    private CustomerService customerService;

    @PostMapping(value = "/oauth2/login")
    R oauthLogin(@RequestBody SocialUser socialUser) throws Exception{
        System.out.printf(socialUser.toString());
        CustomerEntity customerEntity = customerService.login(socialUser);
        System.out.println("-----CustomerController------");
        System.out.println(customerEntity);


        if (customerEntity != null) {
            return R.ok().setData(customerEntity);
        } else {
            return R.error(BizCodeEnum.LOGINACCT_PASSWORD_EXCEPTION.getCode(),BizCodeEnum.LOGINACCT_PASSWORD_EXCEPTION.getMessage());
        }
    }

    @GetMapping (value = "/test")
    R test() {
        // System.out.printf("socialUser.toString()");

        CustomerEntity customerEntity = customerService.test();

        if (customerEntity != null) {
            return R.ok().setData(customerEntity);
        } else {
            return R.error(BizCodeEnum.LOGINACCT_PASSWORD_EXCEPTION.getCode(),BizCodeEnum.LOGINACCT_PASSWORD_EXCEPTION.getMessage());
        }
    }

}
